#ifndef THREAD_H
#define THREAD_H

#include <QObject>
#include <QThread>
#include <QTimer>
#include <QSerialPort>
#include "modbus.h"
#include <QMutex>
#include <QMutexLocker>
#include <QVariant>

//该项目用到的数据交互
typedef   struct Recdata{
    float data_float=0;
    int data_int=0;
    bool data_bool=false;
}Recdata;
class Thread : public QObject
{
    Q_OBJECT
public:
    explicit Thread(QObject *parent = nullptr);
    virtual ~Thread();
signals:
    void sig_runTimer();//运行定时器
    void sig_UpdataUI();//更新UI数据
    void sig_wirteModbus(int Number,QVariant data);
public slots:
    void slots_runTimer();//运行定时器
    void slots_timeOut();//定时超时执行函数
    void slots_wirteModbus(int Number,QVariant data);
public:
    void setRecData(const Recdata &data){
        QMutexLocker Locker(&m_Mutex);
        m_RecData=data;
    }
    const Recdata getRecData(){
        QMutexLocker Locker(&m_Mutex);
        return m_RecData;
    }
protected:
    QSerialPort *m_SerialPort;
    QTimer *m_Timer;
    QThread *m_Thread;
    Recdata m_RecData;
    //寄存器定义
    _MODBUS_DATA data_float;
    _MODBUS_DATA data_int;
    _MODBUS_DATA data_bool;
    //主站设备定义
     ModbusMaster master_1;
     ModbusMaster master_2;

    QMutex m_Mutex;
};

#endif // THREAD_H
